import aiohttp


class SpotBroker(object):
	RequestMethods = ('GET', 'POST', 'PUT', 'DELETE')
	GET, POST, PUT, DELETE = RequestMethods
	
	CandleIntervals = ('1min', '5min', '15min', '30min', 'H', 'D', 'W', 'M')
	M1, M5, M15, M30, H, D, W, M = CandleIntervals
	
	OrderSides = ('Buy', 'Sell')
	Buy, Sell = OrderSides
	
	OrderStatus = (
		'Created', 'Submitted', 'Accepted', 'Partial', 'Filled', 'Revoking', 'Canceled', 'Expired', 'Rejected'
	)
	Created, Submitted, Accepted, Partial, Filled, Revoking, Canceled, Expired, Rejected = OrderStatus
	
	def __init__(self, uri, **kwargs):
		self.uri = uri
		self.headers = {'Content-Type': 'application/json'}
		self.params = kwargs
	
	@staticmethod
	def decimal_to_string(value):
		return None if value is None else ('%f' % value).rstrip('0')
	
	async def http_requests(self, method, path, **kwargs):
		url = self.uri + path
		async with aiohttp.ClientSession() as session:
			async with session.request(method, url, headers=self.headers, **kwargs) as response:
				try:
					response = await response.json()
				except Exception as exp:
					response = await response.text()
					raise TypeError(exp, response)
				else:
					return response
	
	async def basic(self):
		raise NotImplementedError
	
	async def depth(self, symbol):
		raise NotImplementedError
	
	async def kline(self, symbol, interval):
		raise NotImplementedError
	
	async def trade(self, symbol):
		raise NotImplementedError
	
	async def ticker(self, symbol):
		raise NotImplementedError
	
	async def balance(self):
		raise NotImplementedError
	
	async def create_order(self, symbol, mold, side, quantity, line=None, direction=None, price=None):
		raise NotImplementedError
	
	async def cancel_order(self, order_id, symbol):
		raise NotImplementedError
	
	async def order_detail(self, order_id, symbol):
		raise NotImplementedError
	
	async def active_orders(self, symbol):
		raise NotImplementedError
	
	async def history_orders(self, symbol, start, end):
		raise NotImplementedError
	
	async def history_trades(self, symbol, start, end):
		raise NotImplementedError


__all__ = [SpotBroker]
